package main.java.easy;

/**
 * @Author: 郑国荣
 * @Date: 2023-07-21-16:35
 * @Description:
 */
public class LengthOfLastWord {
    public static int lengthOfLastWord(String s){
        int n=s.length()-1;
        if (s.equals("") || n == -1) return 0;
        int count=0;
        while (s.charAt(n)==' '&& n>0) {
            n--;
        }
        while ( n>=0 && s.charAt(n) != ' '){
            count++;
            n--;
        }
        return count;
    }

    public static void main(String[] args) {
        String s=" ";
        System.out.println(lengthOfLastWord(s));
    }
}
